package sphere.controller;

import java.awt.*;
import java.awt.event.*;

import sphere.view.SphereWindow;
import sphere.model.Sphere;

public class SphereController implements KeyListener{
	
	private SphereWindow src;
	private Sphere sp; 

	public SphereController(SphereWindow src){
		this.src = src;
		sp = new Sphere();
	}
	
	@Override
	public void keyPressed(
			KeyEvent e) {
		
	    if (e.getKeyCode() == KeyEvent.VK_ENTER) 
	    {
	    	// Si j'appuie sur le touche ENTREE
		}
		
	}

	@Override
	public void keyReleased(
			KeyEvent e) {

			 if(!(src.getRadiusTextFieldValue().isEmpty()))
			 {
				 // Si j'appuie sur le touche BACKSPACE
				 String radiusText = src.getRadiusTextFieldValue();
			    try{
			    	double radius = Double.parseDouble(radiusText);
			    	sp.setRayon(radius);
			    	src.setRadiusTextFieldColor(Color.WHITE);
			    	src.setVolumeTextFieldValue(""+sp.getVolume());
			   		src.setSurfaceTextFieldValue(""+sp.getSurface());
			   	}
			    catch(NumberFormatException b){
			    	src.setRadiusTextFieldColor(Color.RED);
			    }
			 }
			 else{
				src.setSurfaceTextFieldValue("0");
		    	src.setVolumeTextFieldValue("0");
			 }
	}

	@Override
	public void keyTyped(
			KeyEvent e) {
		
	}
	
}
